from time import sleep
from selenium import webdriver
import unittest

class TestLogin(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.driver = webdriver.Chrome()
        cls.driver.maximize_window()
        cls.driver.implicitly_wait(10)
        cls.driver.get('http://192.168.1.157/index.php/Home/user/login.html')

    def test_login_success(self):
        self.driver.find_element_by_xpath('//*[@id="username"]').send_keys('13800138006')
        self.driver.find_element_by_xpath('//*[@id="password"]').send_keys('123456')
        self.driver.find_element_by_xpath('//*[@id="verify_code"]').send_keys('1111')
        self.driver.find_element_by_xpath('//*[@id="loginform"]/div/div[6]/a').click()

    def test_login_err_username(self):
        self.driver.find_element_by_xpath('//*[@id="username"]').send_keys('13800138001')
        self.driver.find_element_by_xpath('//*[@id="password"]').send_keys('123456')
        self.driver.find_element_by_xpath('//*[@id="verify_code"]').send_keys('1111')
        self.driver.find_element_by_xpath('//*[@id="loginform"]/div/div[6]/a').click()

    def test_login_err_password(self):
        self.driver.find_element_by_xpath('//*[@id="username"]').send_keys('13800138006')
        self.driver.find_element_by_xpath('//*[@id="password"]').send_keys('12345678')
        self.driver.find_element_by_xpath('//*[@id="verify_code"]').send_keys('1111')
        self.driver.find_element_by_xpath('//*[@id="loginform"]/div/div[6]/a').click()

    def tearDown(self) -> None:
        self.driver.refresh()
        sleep(2)

    @classmethod
    def tearDownClass(cls) -> None:
        sleep(1)
        cls.driver.quit()



if __name__ == '__main__':
    unittest.main()




